<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Common\Api\UserApi;
class DirectionalPurchaseController extends BaseController {
    private $adminUser = null;
    public function _initialize(){
    	parent::_initialize();
    	$this->adminUser = new UserApi();

    }
	//获取后台管理员的信息
    public function index(){
      
      $this->display();
    }

   public function DirectionalPurchaseList(){
          $title =I('request.title','','trim');
        if(!empty($title)){
           $where['order_sn | source_order_sn'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }

          $consignee =I('request.consignee','','trim');
        if(!empty($consignee)){
           $where['consignee'] =array('like',"%{$consignee}%");
        }
       $mobile =I('request.mobile','','trim');
        if(!empty($mobile)){
           $where['mobile'] =array('like',"%{$mobile}%");
        }
        $start_time = I('request.start_time','','trim');
        $end_time = I('request.end_time','','trim');

        //如果两个为空，没有条件
        //否则 一个为空，一个有值，两个有值 
        if(!(empty($start_time) && empty($end_time))){ 
            $start_time = empty($start_time)?date("Y-m-d"):$start_time;
            $end_time = empty($end_time)?date("Y-m-d"):$end_time;
            if($start_time>$end_time){
                 $temp=$end_time;
                 $end_time=$start_time;
                 $start_time=$temp;
            }  

         $start_time = strtotime($start_time);
         $end_time = strtotime($end_time);
          $where['create_time'] = array(between,array($start_time,$end_time));
           // $str =" and create_time between '".time($start_time)."' and '".time($end_time)."'"; 
        } 
         $where['isbigorder'] = 1;
         $where['total'] = array('GT',0);
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'create_time desc';
        $_datalist= $this->_getListsFromModel('order_info',$_where_order_field);

        foreach ($_datalist['lists'] as $key => $value) {
            $value['new_address'] = "";
            if(!empty($value['country'])){
                $value['new_address'] =$value['country'].'/';
            }
            if(!empty($value['province'])){
                $value['new_address'] .=$value['province'].'/';
            }
            if(!empty($value['city'])){
                $value['new_address'] .=$value['city'].'/';
            }
            if(!empty($value['district'])){
                $value['new_address'] .=$value['district'].'/';
            }
            if(!empty($value['sign_building'])){
                $value['new_address'] .=$value['sign_building'].'</br>';
            }
            if(!empty($value['address'])){
                $value['new_address'] .=$value['address'];
            }

            //获取详情
             $list = D('order_item')->where('order_id= '.$value['order_id'])->order('id desc')->select();
/*             if(empty($list)){
                unset($_datalist['lists'][$key]);
                continue;
             }*/
             $value['list']=$list;
             $_datalist['lists'][$key] = $value;
        }
        $array =array('正常','已取消','已发货','完成');
        // print_r($_datalist['lists']);exit;
        $this->assign('array',$array);
        $this->assign('lists',$_datalist);
        $this->display();
   }




   //出入库详情
public function DPGoodsDetails(){
  $order_id = I('request.order_id','','trim');
  $this->assign('order_id',$order_id);
  $this->display('goods_details');

}


public function DPGoodsDetailsList(){
  $order_id = I('request.order_id','','trim');
  $where['order_id'] = $order_id;
   $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'id desc';

        $_datalist= $this->_getListsFromModel('order_item',$_where_order_field);
        $this->assign('lists',$_datalist);

 
       $this->display('goods_details_list');
}

}
